<template>
	<view class="tg-parent-view">
		<image class="tuiguang-title" src="../../static/tuiguang-title.png" mode="scaleToFill"></image>
		<view class="qrimg-view">
			<view class="list-view">
				<view v-if="itemCount!=0" class="list-item" @click="onItemClick" :style="itemCount==2||itemCount==4?'width: 316rpx;':'width: 204rpx;'"
				 data-index="我的邀请">
					<text class="item-title">我的邀请</text>
					<text class="item-desc">邀请人数:{{yaoqingCount}}</text>
				</view>
				<view v-if="itemCount!=0" class="list-item" @click="onItemClick" data-index="我的奖励" :style="itemCount==2||itemCount==4?'width: 316rpx;':'width: 204rpx;'">
					<text class="item-title">我的奖励</text>
					<text class="item-desc">获得奖励:{{jiangliCount}}</text>
				</view>
				<view v-if="xiupushiVis" class="list-item" @click="onItemClick" data-index="修谱师" :style="itemCount==2||itemCount==4?'width: 316rpx;':'width: 204rpx;'">
					<text class="item-title">修谱师</text>
					<text class="item-desc">修谱数量:{{xiupushiCount}}</text>
				</view>
				<view v-if="jiapuguanVis" class="list-item" @click="onItemClick" data-index="家谱馆" :style="itemCount==2||itemCount==4?'width: 316rpx;':'width: 204rpx;'">
					<text class="item-title">家谱馆</text>
					<text class="item-desc">查看家谱馆信息</text>
				</view>
				<view v-if="shouyintaiVis" class="list-item" @click="onItemClick" data-index="收银台" :style="itemCount==2||itemCount==4?'width: 316rpx;':'width: 204rpx;'">
					<text class="item-title">收银台</text>
					<text class="item-desc">拾亲增值业务</text>
				</view>
				<view v-if="duihuanmaVis" class="list-item" @click="onItemClick" data-index="兑换码" :style="itemCount==2||itemCount==4?'width: 316rpx;':'width: 204rpx;'">
					<text class="item-title">兑换码</text>
					<text class="item-desc">可用兑换码:{{duihuanmaCount}}</text>
				</view>
			</view>
			<view class="qrimg">
				<tki-qrcode ref="qrcode" :val="QrCode" :size="342" :onval="true" :icon="headIcon" iconSize="35" :loadMake="false"
				 showLoading="true" loadingText="二维码生成中" :usingComponents="true" @result="qrR" />

			</view>
			<view class="save-btn" @click="savePic">我的二维码</view>

			<image class="share-to" src="../../static/icon_tuiguang_share_to.png"></image>

			<button class="share-page-btn" open-type="share">
				<image class="share-image" src="../../static/icon-share-wx.png" mode="scaleToFill"></image>
				<text class="share-text">微信</text>
			</button>

			<text class="down-load-txt" @click="toWeb">更多内容，请打开拾亲App查看详情</text>
		</view>
		<LoginTipDialog :isShow="isShowLoginTip" dataSource="登录查看具体信息" @returnLoginTipDialog="returnLoginTipDialog" />
	</view>
</template>

<script>
	import tkiQrcode from "@/components/tki-qrcode/tki-qrcode.vue"
	import request from '../index/request.js';
	import LoginTipDialog from "@/components/login-tip-dialog/login-tip-dialog.vue";
	export default {
		components: {
			tkiQrcode,
			LoginTipDialog
		},
		data() {
			return {
				isShowLoginTip: false,
				viewHeight: 0,
				QrCode: "",
				src: '', // 二维码生成后的图片地址或base64
				headIcon: "../../static/logo.png",
				appInviteId: "",
				itemCount: 0,
				yaoqingCount: "0",
				jiangliCount: "0",
				
				xiupushiCount: "0",
				xiupushiVis:false,
				jiapuguanCount: "0",
				jiapuguanVis:false,
				duihuanmaCount: "0",
				duihuanmaVis:false,
				shouyintaiCount: "0",
				shouyintaiVis:false
			}
		},
		methods: {
			returnLoginTipDialog: function(e) {
				this.isShowLoginTip = e.isclose
				if (e.tag) {
					uni.navigateTo({
						url: "../index/index"
					})
				}
			},
			onLoad: function(options) {
				this.appUtil.saveAppInviteId(options)
			},
			onShow: function() {
				this.share.path = '/pages/tabBar/home/index?appInviteId=' + this.appUtil.getAppInviteId()
				this.share.shareType = 1
				var user = uni.getStorageSync("shiqin-user")
				if (!user.PQD) {
					this.isShowLoginTip = true
				} else {
					uni.getSystemInfo({
						success: (res) => {
							const wid = res.windowWidth
							const hei = res.windowHeight
							// 230是除了可滚动区域外的其它部分占的rpx高度
							this.viewHeight = hei * 2 + 'rpx'
						}
					});
					this.getQrCode()
					this.getUserAgencyAo()
				}
				this.isShowOperationMember = false
			},
			onItemClick: function(e) {
				var item = e.currentTarget.dataset.index
				switch (item) {
					case '我的邀请':
						uni.navigateTo({
							url: "../my-invite/index"
						})
						break;
						
					case '我的奖励':
						uni.navigateTo({
							url: "../my-rewards/index"
						})
						break;
					case '修谱师':
						var user = uni.getStorageSync("shiqin-user")
						uni.navigateTo({
							url: "../../pagesA/genealogy-museum-xps/index?userPQD="+user.PQD
						})
						break;
					case '家谱馆':
						uni.navigateTo({
							url: "../../pagesA/genealogy-museum/index"
						})
						break;
					case '收银台':
						break;
					case '兑换码':
						break;
				}
				
			},
			getUserAgencyAo: function() {
				var that = this
				request.post("api/user/user_agency_ao", {}).then(data => {
					that.statisticsCash(data)
				})
			},
			statisticsCash: function(result) {
				var that = this
				request.post("api/user/statistics_cash", {}).then(data => {
					that.itemCount = 2
					that.yaoqingCount = result.invite_count + ""
					that.jiangliCount = data.reward + ""
					if (result.correction == '1') {
						that.xiupushiVis=true
						that.itemCount = that.itemCount + 1
						that.xiupushiCount = result.correction_count + ""
					}
					if (result.jpmuseum_user == '1') {
						that.jiapuguanVis=true
						that.itemCount = that.itemCount + 1
						that.jiapuguanCount = result.jpmuseum_user
					}
					if (result.is_cashier == '1') {
						that.shouyintaiVis=true
						that.itemCount = that.itemCount + 1
						that.shouyintaiCount = result.is_cashier
					}
					if (result.ticket_count != 0) {
						that.duihuanmaVis=true
						that.itemCount = that.itemCount + 1
						that.duihuanmaCount = result.ticket_count
					}
				})
			},
			getQrCode: function() {
				var that = this
				request.post("api/user/statistics_cash", {}).then(data => {
					that.QrCode = data.qrcodecontent
					that.jiangliCount = parseInt(data.reward)
				})
			},
			qrR: function(res) {
				this.src = res
			},
			savePic: function() {
				uni.navigateTo({
					url:"../my-qr-code/index"
				})
				// this.$refs.qrcode._saveCode()
			},
			toWeb: function() {
				var that = this
				request.post("api/common/H5_page_v2", {
					id: "150"
				}).then(data => {
					uni.navigateTo({
						url: '/pages/article-details/index?load_url=' +
							encodeURIComponent(data.url) + "&title=" + data.name
					})
				})
			},
		}
	}
</script>

<style>
	@import "index.css";
</style>
